package com.twu.biblioteca.menu;

import com.twu.biblioteca.*;

public class LogInMenuItem implements MenuItem {
    @Override
    public String getName() {
        return "Log In To Your Account";
    }

    @Override
    public String getMnemonic() {
        return "li";
    }

    @Override
    public PostMenuItemAction execute(Library library, UserIO io, UserRepository repository) {
        io.print("Please enter your account number: ");
        String accountNumber = io.readLine();

        io.print("Please enter your password: ");
        String password = io.readPassword();

        if (repository.logIn(accountNumber, password)) {
            io.println("Log in successful.");
        } else {
            io.println("Log in failed. Ensure that you entered your account number and password correctly.");
        }

        return PostMenuItemAction.Continue;
    }

    @Override
    public boolean shouldDisplay(User currentUser) {
        if (currentUser == null) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    public int getPriority() {
        return MenuItem.PRIORITY_USERS;
    }
}
